package com.woniuxy.stage3demo.service.otherPzc.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.stage3demo.bean.otherPzc.ApplyForDataConfigBean;
import com.woniuxy.stage3demo.mapper.otherPzc.ApplyForDataConfigMapper;
import com.woniuxy.stage3demo.pageHelper.PageRequest;
import com.woniuxy.stage3demo.service.otherPzc.IApplyForDataConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(readOnly = true)
public class ApplyForDataConfigServiceImpl implements IApplyForDataConfigService {

    @Autowired
    private ApplyForDataConfigMapper applyForDataConfigMapper;
    /**
     * 新增申请资料
     *
     * @param applyForDataConfig 新增的申请资料对象
     * @return 数据库操作的行数
     */
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public int saveApplyForDataConfig(ApplyForDataConfigBean applyForDataConfig) {
        return applyForDataConfigMapper.saveApplyForDataConfig(applyForDataConfig);
    }

    /**
     * 删除申请资料
     *
     * @param id 删除的申请资料对象的id
     * @return 数据库操作的行数
     */
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public int deleteApplyForDataConfig(int id) {
        return applyForDataConfigMapper.deleteApplyForDataConfig(id);
    }

    /**
     * 修改申请资料
     *
     * @param applyForDataConfig 修改的申请资料对象
     * @return 操作行数
     */
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public int updateApplyForDataConfig(ApplyForDataConfigBean applyForDataConfig) {
        return applyForDataConfigMapper.updateApplyForDataConfig(applyForDataConfig);
    }

    /**
     * 分页查询
     *
     * @param request
     * @param applyForDataConfig
     * @return
     */
    @Override
    public PageInfo<ApplyForDataConfigBean> findAllByParams(PageRequest request, ApplyForDataConfigBean applyForDataConfig) {
        return PageHelper.startPage(request.getPageNum(),request.getLimit()).
                doSelectPageInfo(()->applyForDataConfigMapper.findAllByParams(request,applyForDataConfig));
    }
}
